package com.menggudf.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.menggudf.common.SMS;
import com.menggudf.model.ResultModel;
import com.menggudf.model.UserModel;

@Controller
@RequestMapping("SMS")
public class SMSController {
    
    @RequestMapping("sendMessage")
    @ResponseBody
    public ResultModel sendMessage(
            HttpServletRequest request,
            HttpServletResponse response,
            HttpSession httpSession,
            @RequestParam("phone") String phone){
        
        UserModel userModel = new UserModel();
        
        String templateId = "smsTpl:939cb1f4-9981-417c-9a0b-d4a9b5a990b5";
        int random=(int)(Math.random()*1000000);
        SMS.getSMSSend(templateId,
        Arrays.asList(new String[]{phone}),
        "{\"code\" : \""+random+"\",\"time\" : \"30\"}");
        
        userModel.setSms(String.valueOf(random));
        httpSession.setAttribute("userModel", userModel);
        return ResultModel.success("获取验证码成功", null);
        
    }

}
